﻿using QxFramework.Core;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class PlayerUI : MonoBehaviour
{
    Player player1;
    Player player2;
    Transform player1UI;
    Transform player2UI;
    void Start()
    {
        player1 = TurnController.Instance.player1;
        player2 = TurnController.Instance.player2;
        player1UI = this.transform.Find("Player1UI");
        player2UI = this.transform.Find("Player2UI");
        Refresh();
    }
    /// <summary>
    /// 刷新playerUI面板
    /// </summary>
    public void  Refresh()
    {
        RefreshActionPoint();
        RefreshGradeBar();
        RefreshBackground();
    }
    private void RefreshActionPoint()
    {
        var point1 = player1UI.transform.Find("ActionPoint/Point1");
        var point2 = player1UI.transform.Find("ActionPoint/Point2");
        switch (player1.Movement) 
        {
            case 0:
                point1.GetComponent<Image>().color = new Color32(0,0,0,255);
                point2.GetComponent<Image>().color = new Color32(0, 0, 0, 255);
                break;
            case 1:
                point1.GetComponent<Image>().color = new Color32(255,255,255, 255);
                point2.GetComponent<Image>().color = new Color32(0, 0, 0, 255);
                break;
            case 2:
                point1.GetComponent<Image>().color = new Color32(255, 255, 255, 255);
                point2.GetComponent<Image>().color = new Color32(255, 255, 255, 255);
                break;
        }
        point1 = player2UI.transform.Find("ActionPoint/Point1");
        point2 = player2UI.transform.Find("ActionPoint/Point2");
        switch (player2.Movement)
        {
            case 0:
                point1.GetComponent<Image>().color = new Color32(0, 0, 0, 255);
                point2.GetComponent<Image>().color = new Color32(0, 0, 0, 255);
                break;
            case 1:
                point1.GetComponent<Image>().color = new Color32(255, 255, 255, 255);
                point2.GetComponent<Image>().color = new Color32(0, 0, 0, 255);
                break;
            case 2:
                point1.GetComponent<Image>().color = new Color32(255, 255, 255, 255);
                point2.GetComponent<Image>().color = new Color32(255, 255, 255, 255);
                break;
        }
    }
    private void RefreshGradeBar()
    {
        player1UI.Find("GradeBar/Score").GetComponent<Text>().text = player1.Point.ToString();
        player2UI.Find("GradeBar/Score").GetComponent<Text>().text = player2.Point.ToString();

    }
    private void RefreshBackground()
    {
        Text text = this.transform.Find("BackGroud/Text").GetComponent<Text>();
        if (player1.Movable)
        {
            text.text = "红方回合";
            text.color = Color.red;
        }
        if (player2.Movable)
        {
            text.text = "蓝方回合";
            text.color = Color.blue;
        }
    }
}
